package com.xq.mapper;

import com.xq.pojo.Dept;
import com.xq.pojo.Employee;
import com.xq.vo.EmployeeVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author xq
 * @date 2021/4/3 15:52
 * @version 1.0
 * @description 员工数据接口层
 */
public interface EmployeeMapper2 {
    /**
     * 内连接查询，左表员工表，右边部门表，条件是部门ID   注解方式实现内连接 多对一
     * @return 返回员工和部门对应数据
     */
    @Select("select * from employee a inner join dept b on (a.dept_id = b.dept_id);")
    @ResultMap("com.xq.mapper.EmployeeMapper.EmployeeVoResultMap")
    List<EmployeeVo> getAllInJoinDeptIdObjectAnnotation();

    /**
     * 根据部门ID查询员工的信息，然后根据部门Id查询部门信息  Annotation方式实现内连接 一对多
     * @param deptId 部门ID
     * @return 返回员工和部门对应的数据
     */
    @Select("select * from employee where dept_id = #{deptId};")
    @Results({
            @Result(property = "employeeId",column = "employee_id"),
            @Result(property = "employeeName",column = "employee_name"),
            @Result(property = "employeeSex",column = "employee_sex"),
            @Result(property = "employeeSalary",column = "employee_salary"),
            @Result(property = "employeeAddress",column = "employee_address"),
            @Result(property = "deptId",column = "dept_id"),
            @Result(property = "dept",column = "dept_id", javaType = Dept.class,
                    one = @One(select = "com.xq.mapper.DeptMapper2.getDeptByDeptId")
            )
    })
    List<Employee> getEmployeesByDeptId(Integer deptId);


}
